<template>
    <div class="city">
      <city-header></city-header>
      <city-search :cities="cities"></city-search>
      <city-list :hotCities="hotCities" :cities="cities" :letter="letter"></city-list>
      <city-alphabet :cities="cities" @change="handleLetterChange"></city-alphabet>
    </div>
</template>

<script>
import CityHeader from './components/Header'
import CitySearch from './components/Search'
import CityList from './components/List'
import CityAlphabet from './components/Alphabet'

import axios from 'axios'

export default {
  name: 'City',
  components: {
    CityHeader,
    CitySearch,
    CityList,
    CityAlphabet
  },
  data () {
    return {
      cities: {},
      hotCities: [],
      letter: ''
    }
  },
  methods: {
    getCity () {
      axios.get('/api/city.json').then(this.getCitySuccess)
    },
    getCitySuccess (res) {
      console.log(res)
      if (res.data.ret && res.data) {
        this.cities = res.data.data.cities
        this.hotCities = res.data.data.hotCities
      }
    },
    handleLetterChange (letter) {
      this.letter = letter
    }
  },
  mounted () {
    this.getCity()
  }
}
</script>

<style lang="stylus" scoped>
  .city
    font-size :.3rem
</style>
